package com.ddz.library.view.extend

import android.graphics.PorterDuff
import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.appcompat.widget.AppCompatImageView
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
import com.ddz.library.JKLibrary
import com.ddz.library.resource.toColor

fun AppCompatImageView.setImageSvg(@DrawableRes svgRes:Int, @ColorRes colorRes:Int){
    val color = colorRes.toColor()
    val vectorDrawableCompat = VectorDrawableCompat.create(JKLibrary.context!!.resources,svgRes,JKLibrary.context!!.theme)
    setImageDrawable(vectorDrawableCompat)
    setColorFilter(color,PorterDuff.Mode.SRC_IN)
}
fun AppCompatImageView.setImageSvgDrawable(svgDrawable:Drawable, @ColorRes colorRes:Int){
    val color = colorRes.toColor()
    setImageDrawable(svgDrawable)
    setColorFilter(color,PorterDuff.Mode.SRC_IN)
}
fun AppCompatImageView.setSvgColor(@ColorRes colorRes:Int){
    val color = colorRes.toColor()
    setColorFilter(color,PorterDuff.Mode.SRC_IN)
}